<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('单据查询列表')" />
	<th:block th:include="include :: list-css" />
    <style>
        .layui-tab-title{border-color: #ccc !important;}
        .layui-this{color: rgb(0, 135, 250) !important;background: none !important;}
        .layui-tab-brief > .layui-tab-title .layui-this:after, .layui-tab-brief > .layui-tab-more li.layui-this:after{border-color:  rgb(0, 135, 250) !important;}
        .mid-content {overflow: auto;}
    </style>
</head>
<body class="no-skin">
    <div style="padding:0 10px;">
        <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
    </div>

    <script type="text/html" id="barDh">
        <div class="divdel"></div>
    </script>
    <script type="text/html" id="zjtoolbar">
        <div style="padding: 16px 0;" class="addbtns">
    		
    	</div>
    </script>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: businessJS" />
<script type="text/html" id="buttontext_mj">
    <span>{{d.sellerId ?d.sellerId : '' }}</span>
    <i class="layui-icon layui-icon-more" th:onclick="getMore('sellerId',{{d.LAY_TABLE_INDEX}},'卖家ID','tp_amazonshop',false,false)" style="position:absolute;right:8px;z-index:3"></i>
</script>

<script type="text/html" id="isSign_select">
    <select id="isSign" name="isSign" lay-filter="isSign_select">
        <div th:remove="tag">
            <option></option>
            <option value="否" {{d.isSign == '否'?'selected':''}}>否</option>
            <option value="是" {{d.isSign == '是'?'selected':''}}>是</option>
        </div>
    </select>
</script>
<script type="text/html" id="isSign_countIsShow">
    <input type="checkbox" name="{{d.LAY_TABLE_INDEX}}" value="{{d.countIsShow}}" title="开启|" lay-skin="switch" lay-filter="demo-templet-status" {{d.countIsShow == '0'?'':'checked'}}>
</script>
<!-- <script type="text/html" id="dropdown_mc">
    <select data-field="marketplaceName" lay-filter="select_table" fft="t_dropdown">
        <option></option>
        <div th:each="dict:${amazonShopProduct.marketplaces}" th:utext="'<option value=\''+${dict.id}+'\' {{d.marketplaceId==\''+${dict.id}+'\'?\'selected\':\'\'}}>'+${dict.name}+'</option>'" th:remove="tag"></div>
    </select>
</script> -->

<script th:inline="javascript">
    var gridColumns=''
    var amazonShopProduct = [[${amazonShopProduct}]]
    // var code = [[${parent}]]
    var url = window.location.href;
    window.onload=function(){
        setTimeout(()=>{
        },500)
    }

    moduleTable = "";
    function GetRequest() {
        var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for(var i = 0; i < strs.length; i ++) {
                theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }
    var code=GetRequest(url)
    console.log("code",code)
    code=code.code
</script>
<script>
var $,layer,laydate,form,table;
layui.use(['table','laydate','form','layer','jquery','element'], function () {
	$ = layui.$, layer = layui.layer,laydate = layui.laydate , form = layui.form, table = layui.table, element = layui.element;
    var layCols=[
        {type:'numbers',title:''},
    	{width: 150,field: "code",title: "商品编码",align: "center"},
        {width: 150,field: "sellerSku",title: "<span style='color: red'>*</span>Sku",align: "center",edit:true,},
        {width: 150,field: "asin",title: "Asin",align: "center"},
        {width: 150,field: "fnSku",title: "FnSku",align: "center"},
        {width: 150,field: "isSign",title: "<span style='color: red'>*</span>透明标记",templet: "#isSign_select"},
        {width: 150,field: "signCode",title: "透明标记编码",align: "center",edit:true},
        {width: 200,field: "sellerId",title: "<span style='color: red'>*</span>平台编号",align: "center",edit:true,templet: "#buttontext_mj"},
    	{width: 150,field: "shopName",title: "店铺名称",align: "center"},
    	{width: 150,field: "marketplaceName",title: "区域名称",},
        {width: 150,field: "countIsShow",align: "center",title: "是否开启运营跟踪",templet:"#isSign_countIsShow"},
    	{width: 150,field: "shopGuid",title: "店铺标识",align: "center",hide:true},
    	{width: 150,field: "marketplaceId",title: "区域标识",align: "center",hide:true},
    	{width: 150,field: "guid",title: "唯一标识",align: "center",hide:true},
    	{align: "center",title:'操作', toolbar: '#barDh', width:100,fixed: 'right'}
    ];

    $.tablelist.init({
    	elem: '#dhtable'
    	,data: amazonShopProduct
    	,page: false
    	,even: true
    	,limit: 1000
    	,cols: [layCols]
    	,height:'full-0'
        , toolbar: '#zjtoolbar'
    	,done:function(res, curr, count){
            listData = table.cache.dhtable;//每次重载都赋值更新表缓存
            changeDropdownInTable('isSign',listData);
            qx()
    	}
    });

    function qx(){
        var btnstr=''
            if(parent.extraButton.xzbmbtn){
                btnstr+=`<div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addbtn"  style="margin:0 10px;height: 35px;">
                    <p style="color:white;font-size:14px;"><span class="fa_span">新增明细</span></p>
                </div>`
            }else{
                btnstr+=`<div class="layui-btn layui-btn-normal layui-table-tools"  style="margin:0 10px;height: 35px;background-color:#ddd !important;border:none;color:#999;">
                    <p style="color:white;font-size:14px;"><span class="fa_span">新增明细</span></p>
                </div>`
            }
            $('.addbtns').html(btnstr)

            var divdel=''
            if(parent.extraButton.scbmbtn){
                divdel+=`<button class="layui-btn layui-btn-danger layui-btn-xs dhicon dh-remove"  lay-event="del">&nbsp;删除</button>`
            }else{
                divdel+=`<button class="layui-btn layui-btn-disabled layui-btn-xs dhicon dh-remove">&nbsp;删除</button>`
            }
            $('.divdel').html(divdel)
    }

    // 状态 - 开关操作
    form.on('switch(demo-templet-status)', function(obj){
        var id = this.value;
        var name = this.name;
        if(obj.elem.checked){
            obj.elem.value = 1;
        }else {
            obj.elem.value = 0;
        }
        var rowIndex = parseInt(name);
        amazonShopProduct[rowIndex].countIsShow= obj.elem.value;
        table.reload('dhtable', {data : amazonShopProduct});
    });

    //监听单元格编辑
    table.on('edit(ftable)', function(obj){
        var rowIndex = +$(obj.tr).attr("data-index");
        amazonShopProduct[rowIndex]=obj.data
        table.reload('dhtable', {data : amazonShopProduct});
    });

    //监听行事件
    table.on('tool(ftable)', function (obj) {
        console.log(obj)
        switch (obj.event) {
            case "del":
            layer.confirm('是否确定删除', {btn : ['确定', '取消']}, function(index) {
                $.post('/hr/amazonshopproduct/delete', {'infoItems':JSON.stringify([obj.data])} ,function(result){
                    layer.msg(result.msg)
    		    	if(result.code==0){
                        window.location.reload()
                    };
    		    });
            })

            break;
        }
    });

    //头工具栏事件
    table.on('toolbar(ftable)', function (obj) {
        switch (obj.event) {
            case 'addbtn':
                amazonShopProduct.push({code:code});
                table.reload('dhtable', {data : amazonShopProduct});
                form.render();
                break;

        };
    });

})

function getMoreAfter(fieldsList,fields,tindex,fieldName,fieldSearchType,isSearch,isLayer,res){
    amazonShopProduct[tindex].sellerId=res.sellerId
    amazonShopProduct[tindex].shopName=res.shopName
    amazonShopProduct[tindex].marketplaceName=res.countryName
    amazonShopProduct[tindex].shopGuid=res.guid
    amazonShopProduct[tindex].marketplaceId=res.marketplaceIds
    table.reload('dhtable', {data:amazonShopProduct});
}

</script>

</body>
</html>